#ifndef __GLOBAL_H_
#define __GLOBAL_H_

#define XBDRIVE_STD

#include <Arduino.h>
#include <XBDrive/APP/Settings.h>
#include <XBDrive/MotorCtrl/CaliTab.h>
#include <XBDrive/MotorCtrl/stepper_controller.h>
#include <XBDrive/MotorCtrl/stepper_input.h>
#include <XBDrive/MotorCtrl/OperationalMode.h>
#include <XBDrive/SLB/SinCosLUT.h>
#include <XBDrive/SLB/mymath.h>
#include <XBDrive/MotorCtrl/tempSensor.h>
#include <XBDrive/MotorCtrl/PowerVoltage.h>
#include <XBDrive/HDL/hdl.h>
#include <XBDrive/APP/move.h>
#include <XBDrive/APP/calibration.h>
#include <XBDrive/APP/poweron.h>
#include <XBDrive/APP/communication.h>
#include <XBDrive/APP/callback.h>
#include <XBDrive/APP/zerosignal.h>
#include <XBDrive/APP/Error.h>
#include <XBDrive/APP/Defaults.h>
#include <XBDrive/APP/SettingsDefinitions.h>

extern HardwareSerial *DEBUG_port;

extern volatile int16_t kp;
extern volatile int16_t ki;
extern volatile int16_t kd;

extern volatile int32_t step_input;         //外部控制脉冲输入定时器的值
extern volatile int32_t step_input_offset;  //上电初始外部控制脉冲输入偏移值
extern volatile int32_t motor_pos_set;      //指令电机位置
extern volatile int32_t motor_pos_set_last;
extern volatile uint8_t dir;                //电机旋转方向
extern volatile int32_t encoder_cnt;        //编码器的读数值
extern volatile int32_t encoder_cnt_last;
extern volatile int32_t motor_pos;          //实际电机位置值
extern volatile int32_t motor_pos_last;
extern volatile int32_t advance;            //电机控制提前角度
extern volatile int32_t motor_rev_cnt;      //电机旋转圈数
extern volatile int32_t motor_pos_err;      //误差值等于指令电机位置值减去实际电机位置值
extern volatile int32_t pid_iterm;          //PID控制i积分项
extern volatile int32_t pid_dterm;          //PID控制d微分项
extern volatile int32_t vector_current;     //矢量控制电流大小
extern volatile int32_t stepangle;          //电子齿轮值

extern volatile int32_t half_current_cnt;   //开环模式下半流控制计数值
extern volatile uint8_t closedloop_mode;    //开环闭环模式标志位

#endif
